package ptaPartTwo;
import java.util.Scanner;
public class FiveThree {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		String []str = new String[n];
		String str1,str2;
		for(int i=0;i<n;i++)
		    str[i]=input.next();
		for(int i=0;i<n-1;i++)
			for(int j=0;j<n-1-i;j++)
			{
				str1=str[j].substring(6, 14);
				str2=str[j+1].substring(6, 14);
				if(Integer.parseInt(str1) > Integer.parseInt(str2))
				{
					str1=str[j];
					str[j]=str[j+1];
					str[j+1]=str1;
				}
			}
		while(input.hasNext())
		{
			String Str3;
			Str3=input.next();
			if(Str3.equals("sort2")){
				for(int i=0 ;i<n;i++)
				System.out.println(str[i]);
			}
			if(Str3.equals("sort1")){
			    for(int i=0 ;i<n;i++)
			    System.out.println(str[i].substring(6,10)+"-"+str[i].substring(10,12)+"-"+str[i].substring(12,14));
			}
			if(!Str3.equals("sort2")&&!Str3.equals("sort1")){
				System.out.println("exit");
			}
		}

	}
	
}
